package com.ming.transaction.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.transaction.common.Result;
import com.ming.transaction.common.annotation.RecordLoggerAnnotation;
import com.ming.transaction.entity.Wbuy;
import com.ming.transaction.service.IWbuyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 求购商品表 前端控制器
 * </p>
 *
 * @author 陈仕健
 * @since 2023-05-10
 */
@Api(tags = "求购商品控制器")
@RestController
@RequestMapping("/wbuy")
public class WbuyController {

    @Resource
    private IWbuyService wbuyService;

    /**
     * 分页查询商品
     * @param pageNum
     * @param pageSize
     * @param product
     * @param unumber
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("求购商品分页查询")
    public Result pageSeach(@RequestParam Integer pageNum,
                            @RequestParam Integer pageSize,
                            @RequestParam(defaultValue = "") String product,
                            @RequestParam(defaultValue = "") String unumber){
        return wbuyService.pageSach(pageNum,pageSize,product,unumber);
    }

    /**
     * 添加求购商品
     * @param wbuy
     * @return
     */
    @PostMapping
    @ApiOperation("添加求购商品")
    @RecordLoggerAnnotation(value = "用户添加求购商品")
    public Result addPuct(@RequestBody Wbuy wbuy){
        return wbuyService.savePuct(wbuy);
    }

    /**
     * 批量删除商品
     * @param ids
     * @return
     */
    @ApiOperation("批量删除求购商品")
    @PostMapping("/del/batch")
    @RecordLoggerAnnotation(value = "批量删除求购商品")
    public Result delBatch(@RequestBody List<Integer> ids){
        return wbuyService.delBat(ids);
    }

    /**
     * 修改求购商品
     * @param wbuy
     * @return
     */
    @ApiOperation("修改求购商品信息")
    @PutMapping
    @RecordLoggerAnnotation(value = "修改求购商品信息")
    public Result upPuct(@RequestBody Wbuy wbuy){
        return wbuyService.upPuct(wbuy);
    }

    /**
     * 删除与用户匹配ID的求购商品
     * @param id
     * @return
     */
    @ApiOperation("删除与用户匹配ID的求购信息")
    @DeleteMapping("/{id}")
    @RecordLoggerAnnotation(value = "删除求购商品信息")
    public Result delPuct(@PathVariable("id") Integer id){
        return wbuyService.delById(id);
    }
}

